﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Managers;
using Providers.LiveControl.Server;
using System.Windows.Forms;

namespace WindowApiConsle
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            TestDic();
            //TestNovaServer();
            //TestApi();
            //TestClipboard();
            TestScrean();
            Console.ReadLine();
        }

        private static void TestDic()
        {
            Dictionary<string,string> strDictionary =new Dictionary<string, string>();
            strDictionary["test"] = "test";
            strDictionary["test"] = "test";
            strDictionary["test"] = "test";
            strDictionary["test"] = "test";
            Console.WriteLine(strDictionary.Count);
        }

        private static void TestScrean()
        {
            var screens = Screen.AllScreens;
            foreach (var screen in screens)
            {
                
                Console.WriteLine(screen.Bounds.ToString());
            }
        }

        private static string[] strArry()
        {
            string[] strings = new[]
            {
                "DataObjectAttributes",
                "DataObjectAttributesRequiringElevation",
                "FileGroupDescriptorW",
                "FileContents",
                "Preferred DropEffect",
                "UIDisplayed",
                "DropDescription",
                "AsyncFlag",
                "TVClipboard",
            };
            return strings;

        }

        private static void TestClipboard()
        {
            string[] strings = new[]
              {
                "DataObjectAttributes",
                "DataObjectAttributesRequiringElevation",
                "FileGroupDescriptorW",
                "FileContents",
                "Preferred DropEffect",
                "UIDisplayed",
                "DropDescription",
                "AsyncFlag",
                "TVClipboard",
            };

            while (true)
            {
              
                    foreach (var str in strings)
                    {
                    try
                    {
                        MemoryStream stream = (MemoryStream)Clipboard.GetData(str);
                        stream.GetBuffer();
                        Console.WriteLine(stream.GetBuffer());
                        
                        Console.WriteLine($"{str}的流信息：");

                        Console.ReadLine();
                    }
                    catch (Exception)
                    {

                    }
                }
                
                

            }
        }
        private static void TestNovaServer()
        {
            //var ret = NovaServer.Instance.NovaManager.GeneratePassword();

            //Console.WriteLine(ret.Result.NewPassword);
            //Console.WriteLine(NovaServer.Instance.NovaManager.Provider.ServerMachine.Identity);

            //var retId = NovaServer.Instance.NovaManager.RegisterWithIntroducerAsTask();
            //Console.WriteLine(retId.Result.NovaId);

            //Console.WriteLine("RegisterWithIntroducerAsTask 完成");
        }

        private static void TestApi()
        {
            var processes = WindowApi.GetProcesses();
            Console.ReadLine();

            var ptr = WindowApi.WindowFromPoint(20, 20);

            var length = WindowApi.GetWindowTextLength(ptr);
            var windowName = new StringBuilder(length + 1);
            WindowApi.GetWindowText(ptr, windowName, windowName.Capacity);
            try
            {
                Console.WriteLine($"_________________________________________________________");
                Console.WriteLine($"ProcessName:{windowName},Handle:{ptr},HandleInt:{ptr.ToInt32()}");
                var rect = WindowApi.GetRect(ptr.ToInt32());
                Console.WriteLine(
                    $"Top:{rect.Rect.Top},Left:{rect.Rect.Left},Width:{rect.Rect.Right - rect.Rect.Left},Height:{rect.Rect.Bottom - rect.Rect.Top}");

                WindowApi.Highlight(ptr);
                Console.WriteLine($"_________________________________________________________");
                Console.WriteLine($"按任意显示最小状态");
                //WindowApi.ClearHighlight(ptr);

                Console.ReadLine();
                var isIco = WindowApi.IsIconic(ptr);
                if (isIco)
                {
                    Console.WriteLine($"最小了");
                }
                else
                {
                    Console.WriteLine($"不是最小");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}